package com.example.demo;

import com.example.demo.annotions.WebPath;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.Map;

/**
 * Created by Arat.Wu on 2018/10/08.
 */
@Component
public class WebPathScanner implements BeanPostProcessor{

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        Service annotationService = AnnotationUtils.findAnnotation(bean.getClass(), Service.class);
        if(null != annotationService) {
            Method[] methods = bean.getClass().getMethods();
            methods = ReflectionUtils.getUniqueDeclaredMethods(bean.getClass());

            for (Method method : methods) {
                WebPath annotation = AnnotationUtils.findAnnotation(method, WebPath.class);
                if (annotation != null) {
                    System.out.println("===========");
                }
            }
        }

        return bean;
    }
}
